package e

import (
	"community-service/pkg/errorx/pb"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

func NewGrpcErr(code codes.Code, errCode uint32) error {
	details, _ := status.New(code, MapErrMsg(errCode)).WithDetails(&pb.Error{
		Code: int32(errCode),
		Msg:  MapErrMsg(errCode),
	})
	return details.Err()
}

func NewMsgGrpcErr(errCode uint32, msg string) error {
	details, _ := status.New(codes.Canceled, MapErrMsg(errCode)).WithDetails(&pb.Error{
		Code: int32(errCode),
		Msg:  msg,
	})
	return details.Err()
}

func IsCodeErr(code uint32) bool {
	if _, ok := message[code]; ok {
		return ok
	}
	return false
}
